<template>
	<view>
		<view v-if="islog" class="flex j-c a-c" style="height: 180rpx;background-color: #fff;">
			<image style="width: 50rpx;height: 50rpx;" src="@/static/lo.gif"></image>
		</view>
		<view v-if="!islog" class="pr2 pl2 pb2" v-for="(item,index) in list" :key="index">
			<view class="p20 b_y flex" style="background-color: #fff;">
				<view class="" @click="item.residue<=0||times(item,1)||times(item,2)?'':on_view(item)"
					style="position: relative;width: 160rpx;height: 160rpx;">
					<image class="b_y" style="width: 160rpx;height: 160rpx;position: absolute;z-index: 9;" :src="item.pic">
					</image>
					<view class="mc" v-if="item.residue<=0">已抢光</view>
					<view class="mc" v-if="times(item,1)">未开始</view>
					<view class="mc" v-if="times(item,2)">已结束</view>
				</view>
				<view @click="item.residue<=0||times(item,1)||times(item,2)?'':on_view(item)"
					style="margin-left: 10rpx;width:450rpx ;">
					<text class="f30 w800 ml1 yihang" style="width: 350rpx; overflow: hidden;">{{item.name}}</text>
					<!-- 	<view class="pt1  yihang" style="width: 400rpx;">
						<text class="yuanzi f26"  v-if="indexa<3"  v-for="(vo,indexa) in item.tag">{{vo}}</text>
					</view> -->
					<view class="pt1 yihang" style="margin-left: 15rpx;">
						<text class="f26" style="color: #999999;">活动时间:{{item.beginTime}}-{{item.endTime}}</text>
					</view>
					<view class="pt1 yihang" style="margin-left: 15rpx;">
						<text class="f26 ff"
							:style="item.actplatform==1?'background-color:#FDC400;':'background-color:#0192FF;'">实付满<text
								class="st">{{item.paidin}}</text>返<text class="st">{{item.commission}}</text></text>
						<text class="f26" style="color: #999999;margin-left: 20rpx;">剩余:{{item.residue}}份</text>
					</view>
					<view class="pt1 yihang" style="margin-left: 15rpx;">
						<text class="f26"
							style="color: #999999;">距离商家{{item.distance>999?(item.distance/1000).toFixed(2)+'km':item.distance+'m'}}</text>
					</view>
					<!-- 	<view   v-if="type==2&&item.status==0" class="pt1 yihang" style="margin-left: 15rpx;">
						<text class="f26 cred" >拒绝原因:{{item.refuse_text}}</text>
					</view> -->
				</view>
				<view @click="on_tel(item.shop_tel)" class="pt3 t_c"
					style="display: flex;flex-direction: column;justify-content: center;">
					<image v-if="item.actplatform==1" style="width: 70rpx;height: 70rpx;" src="@/static/tab/mt.png"></image>
					<image v-if="item.actplatform==2" style="width: 70rpx;height: 70rpx;" src="@/static/tab/elm.png"></image>
					<view class="f24 c_7" v-if="item.distance>0">
						<text></text>
					</view>
				</view>
			</view>

			<view class="flex j-f p2" v-if="type==2">
				<text class="banmi_button_2" style="background-color: #4169E1;">
					{{item.status==0?'已拒绝': item.status==1?'审核中': item.status==2?'已上线': '取消收藏'	}}
				</text>
				<text @click="on_edit(index)" class="banmi_button_2 ml1">编辑</text>
				<text @click="on_del(index)" class="banmi_button_del ml1">删除</text>
			</view>
			<view @click="on_del(index)" class="flex j-f p2" v-if="type==1">
				<text class="banmi_button_del ml2">删除</text>
			</view>
		</view>
		<!-- 有用 -->
	<!-- 		<view v-if="!islog&&list.length>10" class="flex j-c a-c" style="height: 180rpx;">
			<text class="f24 c_pl1">{{log}}</text>
		</view> -->
<!-- 		<view class="" v-if="!lat">
			<view class="flex a-c j-c" style="padding-top: 80px;padding-bottom: 50rpx;background-color: #fff;">
				<text class="c_pl1">定位未开启</text>
			</view>
		</view> -->
		<view v-if="!islog&&list.length==0" class="flex j-c a-c" style=" background-color: #fff;">
			<!-- <text class="f24 c_pl1">暂无数据</text> -->
			<image src="../../static/tab/null.png" v-if="lat" style="width:400rpx;height:400rpx;margin-top: 40rpx;" mode="aspectFill">
			</image>
			<image src="../../static/tab/wz.png" v-if="!lat" style="width:400rpx;height:400rpx;margin-top: 40rpx;" mode="aspectFill">
			</image>
		</view>
	</view>
</template>

<script>
	export default {

		props: {
			options: {
				type: Object,
				default: function(e) {
					return {}
				}
			},
			list: {
				type: Array,
				default: function() {
					return [] //数据
				},
			},
			islog: {
				type: Boolean, //是否显示边框
				default: true
			},
			log: {
				type: String,
				default: ''
			},
			qiniu: {
				type: String,
				default: ''
			},
			tabindex: {
				type: Number,
				default: 0
			},
			index: {
				type: Number,
				default: 0
			},
			time: {
				type: Number,
				default: 0
			},
			type: {
				type: Number,
				default: 0
			},
		},

		filters: {
			timeStamp1: function(timestamp) {

				function zeroize(num) {
					return (String(num).length == 1 ? '0' : '') + num;
				}

				var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
				var timestampDiff = curTimestamp - timestamp; // 参数时间戳与当前时间戳相差秒数

				var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
				var tmDate = new Date(timestamp * 1000); // 参数时间戳转换成的日期对象

				var Y = tmDate.getFullYear(),
					m = tmDate.getMonth() + 1,
					d = tmDate.getDate();
				var H = tmDate.getHours(),
					i = tmDate.getMinutes(),
					s = tmDate.getSeconds();

				if (timestampDiff < 60) { // 一分钟以内
					return "刚刚";
				} else if (timestampDiff < 3600) { // 一小时前之内
					return Math.floor(timestampDiff / 60) + "分钟前";
				} else if (curDate.getFullYear() == Y && curDate.getMonth() + 1 == m && curDate.getDate() == d) {
					return '今天' + zeroize(H) + ':' + zeroize(i);
				} else {
					var newDate = new Date((curTimestamp - 86400) * 1000); // 参数中的时间戳加一天转换成的日期对象
					if (newDate.getFullYear() == Y && newDate.getMonth() + 1 == m && newDate.getDate() == d) {
						return '昨天' + zeroize(H) + ':' + zeroize(i);
					} else if (curDate.getFullYear() == Y) {
						return zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
					} else {
						return Y + '年' + zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
					}
				}
			}

		},
		data() {
			return {
				lat: '',
				lng: '',
			}
		},
		mounted() {
			this.lat = uni.getStorageSync('latitude')
			this.lng = uni.getStorageSync('longitude')
		},


		methods: {
			times(item, i) {
				const date = new Date();
				const hours = date.getHours();
				const minutes = date.getMinutes();
				let t = hours + '' + (minutes < 10 ? "0" : "") + minutes //当前时间
				let beg = item.beginTime.replace(':', '')
				let end = item.endTime.replace(':', '')
				if (i == 1) { //判断活动是否开始
					if (parseInt(t) < parseInt(beg)) { //当前时间小于开始时间说明活动已经未开始
						return true
					} else {
						return false
					}
				} else if (i == 2) {
					if (parseInt(t) > parseInt(end)) {
						return true
					} else {
						return false
					}
				}
			},
			on_edit(index) {
				uni.switchTab({
					url: '/pages/ban_tongchengshop/shop_add'
				})
			},
			on_del(index) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认删除？',
					success: function(res) {
						if (res.confirm) {
							that.$emit('on_del', index)
						}
					}
				});
			},
			on_view(item) {
				this.$module.navigateTo('/page1/ban_tongchengshop/shop_view?item=' + JSON.stringify(item))
				// var id = this.list[index]['id']
				// uni.navigateTo({
				// 	url: '/pages/ban_tongchengshop/shop_view?id=' + id
				// })
			},
			// on_tel(phone) {
			// 	uni.makePhoneCall({
			// 		phoneNumber: phone,
			// 		success: function() {
			// 		}
			// 	})
			// }
		}
	}
</script>

<style>
	.ff {
		padding: 8rpx 14rpx;
		color: #fff;
		border-radius: 20rpx;
		font-size: 25rpx;
	}

	.st {
		font-size: 26rpx;
		padding: 0 2rpx;
		font-weight: bold;
	}

	.mc {
		position: absolute;
		background-color: #4e4e4ec7;
		color: #fff;
		text-align: center;
		z-index: 990;
		line-height: 160rpx;
		padding: 0 10rpx;
		width: 140rpx;
		height: 160rpx;
	}
</style>